import Vue from 'vue'

export default {
  /**
   * 获取cookie  by Nadia
   */
  getCookie: function (key) {
    if (document.cookie.length > 0) {
      var start = document.cookie.indexOf(key + '=')
      if (start !== -1) {
        start = start + key.length + 1
        var end = document.cookie.indexOf(';', start)
        if (end === -1) end = document.cookie.length
        return unescape(document.cookie.substring(start, end))
      }
    }
    return ''
  },
  /**
   * 保存Cookie by Nadia
   * @param c_name
   * @param value
   * @param expiredays
   */
  setCookie: function (cName, value, expiredays) {
    var exdate = new Date()
    exdate.setDate(exdate.getDate() + expiredays)
    document.cookie = cName + '=' + decodeURIComponent(value) +
      ((expiredays == null) ? '' : ';expires=' + exdate.toGMTString())
  },
  /**
   * 消息提示框
   * 新增、修改、删除、审核、驳回等操作调用该提示框
   * type 只有success和warning
   **/
  setMessage: function (type, message,showClose) {
    Vue.prototype.$message({
      showClose: showClose,
      message: message,
      type: type,
      duration: 2000
    })
  },
  /**
   * 注销登录
   */
  logout: function () {
    this.setCookie('token', '')
    this.setCookie('accountId', '')
    window.location.reload()
  }
}
